@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row">
        <div class="col-md-12">
            <div class="panel panel-default">
                <div class="panel-heading">Dashboard</div>

                <div class="panel-body">
                    @if (session('status'))
                        <div class="alert alert-success">
                            {{ session('status') }}
                        </div>
                    @endif
                    <table class="table table-hover table-striped">
                      <thead>
                        <tr>
                          <th>ID</th>
                          <th>Url</th>
                          <th>Latest Record</th>
                          <th>Recorded At</th>
                          <th>
                            <span class="glyphicon glyphicon-cog"></span>
                          </th>
                        </tr>
                      </thead>
                      <tbody>
                        @foreach($websites as $v)
                        <tr>
                          <td>#{{$v['id']}}</td>
                          <td>{{$v['url']}}</td>
                          <td>
                            @if(isset($v['record']))
                              <span class="label label-{{$v['record']['status_code'] == 200?'success':'danger'}}">{{$v['record']['status_code']}}</span>
                            @else
                              <span class="label label-default">None</span>
                            @endif
                          </td>
                          <td>
                            @if(isset($v['record']))
                              {{$v['record']['created_at']->diffForHumans()}}
                            @else
                              <span class="label label-default">None</span>
                            @endif
                          </td>
                          <td>
                            <a href="/records/{{$v['id']}}" data-toggle="tooltip" data-placement="top" title="View Records"  class="btn btn-sm btn-primary glyphicon glyphicon-eye-open"></a>
                            <a href="/delete-monitor/{{$v['id']}}" data-toggle="tooltip" data-placement="top" title="Delete Monitor" onclick="return confirm('Confirm Delete ?')" class="btn btn-sm btn-danger glyphicon glyphicon-trash"></a>
                          </td>
                        </tr>
                        @endforeach
                      </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection
